import numpy as np
import pandas as pd
arr=np.random.randint(1,20,size=(3,3))
df=pd.DataFrame(arr,columns=['c','b','a'])
print('原始数据:\n',df)
print('按行索引降序排序:\n',df.sort_index(ascending=False))
print('按列标签升序索引:\n',df.sort_index(axis=1))

import numpy as np
import pandas as pd
arr=np.random.randint(1,20,size=(3,3))
df=pd.DataFrame(arr,columns=['c','b','a'])
print('原始数据:\n',df)
print('按第2行的值升序排序:\n',df.sort_values(by=1,axis=1))
print('按第2列的值升序排序:\n',df.sort_values(by=1))
df.columns=['a','b','c']
print('设置列标签后的原始数据:\n',df)
print('按a列的值降序排序:\n',df.sort_values(by='a',ascending=False))

import pandas as pd
pd.set_option('display.unicode.east_asian_width',True)
df=pd.DataFrame([2,5,5,5,10,3,4,12,7,10],columns=['原始数据'])
df['顺序排名']=df['原始数据'].rank(method='first')
df['最大值排名']=df['原始数据'].rank(method='max')
df['最小值排名']=df['原始数据'].rank(method='min')
df['最小值排名']=df['原始数据'].rank(method='min')
df['平均值排名']=df['原始数据'].rank(method='average')
print(df)